﻿using TSharp.Core.Util.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using TSharp.Security.RSA.Standard;
using TSharp.Core.Util.Numeric;
using TSharp.Core.TestUtil;

namespace Wicresot.CoreTests
{
     

    /// <summary>
    ///这是 CodecTest 的测试类，旨在
    ///包含所有 CodecTest 单元测试
    ///</summary>
    [TestClass()]
    public class CodecTest
    {
        private TestContext testContextInstance;

        /// <summary>
        ///获取或设置测试上下文，上下文提供
        ///有关当前测试运行及其功能的信息。
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region 附加测试特性
        // 
        //编写测试时，还可使用以下特性:
        //
        //使用 ClassInitialize 在运行类中的第一个测试前先运行代码
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //使用 ClassCleanup 在运行完类中的所有测试后再运行代码
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //使用 TestInitialize 在运行每个测试前先运行代码
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //使用 TestCleanup 在运行完每个测试后运行代码
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///XToH 的测试
        ///</summary>
        [TestMethod()]
        public void XToHTest()
        {

            Assert.AreEqual("12345", Codec.XToH(12345, 10));
            Assert.AreEqual("765324", Codec.XToH(0x765324, 16));
            Assert.AreEqual("edabc234", Codec.XToH(0xedabc234, 16));
            Assert.AreEqual("edabc234", Codec.XToH(0xedabc234, 16));
            Assert.AreEqual("3SEHH9HZSFEX33IJL4BBRWPHD", new BigInteger("3SEHH9HZSFEX33IJL4BBRWPHD", 36).ToString(36));


            long v = 61;
            var actal = Codec.XToH(v, 62);
            Console.WriteLine(actal);
            Console.WriteLine(Codec.HToX(actal, 62));
            Console.WriteLine(v);
            Console.WriteLine();

            Console.WriteLine(Codec.HToX("1", 62));
            Console.WriteLine(Codec.HToX("Z", 62));
            Assert.AreEqual("edabc234", Codec.XToH(0xedabc234, 16));
            Assert.AreEqual("EDABC234", new BigInteger(0xedabc234).ToHexString());
            Console.WriteLine();
            BigInteger a = new BigInteger(long.MaxValue);
            BigInteger b = new BigInteger(long.MaxValue);
            Console.WriteLine(a.ToHexString() + " ?= " + long.MaxValue);


            Console.WriteLine(factorial(240).ToString(36));
        }

        BigInteger factorial(BigInteger start)
        {
            if (start <= 0)
                return 1;
            if (start < 2)
                return start;
            return start * factorial(start - 1);
        }
        [TestMethod()]
        public void Test()
        {
            BigInteger a = new BigInteger(long.MaxValue);
            BigInteger b = new BigInteger(long.MaxValue);
            BigInteger c = factorial(240);
            BigInteger_69 d = new BigInteger_69(c.getBytes());

            Performance.MeasurePerformance(
                "",
                10000,
                x =>
                {
                    d.ToString(36);
                },
                x =>
                {
                    c.ToString(36);
                });
        }
    }
}
